﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ClassLibrary1.entity;
using ConsoleApplication1;

namespace WindowsFormsApplication1
{
    public partial class Form2 : Form
    {
        Form1 root;

        public Form2(Form1 root)
        {
            InitializeComponent();

            this.root = root;

            foreach (var i in Data.types)
            {
                this.comboBox1.Items.Add(i.Name.ToLower());
            }
            comboBox1.SelectedItem = "car";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            List<string> list = new List<string>();
            list.Add("add");
            
            list.Add(comboBox1.SelectedItem.ToString().ToLower());

            if (textBox1.Text.Trim() != "")
            {
                try
                {
                    int.Parse(textBox1.Text);
                    list.Add(textBox1.Text);
                }
                catch (Exception)
                {
                    MessageBox.Show("Недопустимое значение id");
                    textBox1.Clear();
                }
            }
            try
            {
                CProgram.RunCommand(list.ToArray());
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }
            this.Dispose();
            this.Close();
            root.cbox_entity_SelectedIndexChanged(null, null);
        }
    }
}
